﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RenameTool.CApRenameElement
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EMPMODELLib;
using EMPTYPELIBRARYLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Media;
using Tecnomatix.Engineering;
using Tecnomatix.Planning.DotNetFoundation;


namespace DnProcessSimulateCommands.RenameTool;

public class CApRenameElement : 
  INotifyPropertyChanged,
  IComparable<CApRenameElement>,
  IComparer<CApRenameElement>,
  IComparable
{
  private CheckStatusDelegate checkStatus;
  private ImageSource _icon;
  private EmpObjectKey key;
  private ITxObject obj;
  private DnfClassDef _classDef;
  private string _name;
  private string _preview;
  private string _objectType;
  private bool _isChecked = true;
  private Dictionary<string, string> attributeValue;

  public event CheckStatusDelegate Checked;

  public CApRenameElement()
  {
  }

  public CApRenameElement(EmpObjectKey obj, EmpContext context, CheckStatusDelegate func)
  {
    EmpObject empObject = (EmpObject) new EmpObjectClass();
    this.key = obj;
    this.Name = (string) ((IEmpObject) empObject).GetField(ref context, ref this.key, "name").Value;
    this.Preview = this.Name;
    this.checkStatus = func;
  }

  public CApRenameElement(
    ITxObject obj,
    CheckStatusDelegate func,
    GetObjectNameFunc getObjectNameMethod)
  {
    this.obj = obj;
    this.checkStatus = func;
    try
    {
      this.Name = getObjectNameMethod(obj);
      this.Preview = this.Name;
    }
    catch (Exception ex)
    {
    }
  }

  public DnfClassDef ClassDef
  {
    get => this._classDef;
    set => this._classDef = value;
  }

  public ITxObject Obj
  {
    get => this.obj;
    set => this.obj = value;
  }

  public EmpObjectKey Key
  {
    get => this.key;
    set => this.key = value;
  }

  public ImageSource Icon
  {
    get => this._icon;
    set => this._icon = value;
  }

  public string Name
  {
    get => this._name;
    set
    {
      this._name = value;
      this.NotifyPropertyChanged(nameof (Name));
    }
  }

  public string Preview
  {
    get => this._preview;
    set
    {
      this._preview = value;
      this.NotifyPropertyChanged(nameof (Preview));
    }
  }

  public string ObjectType
  {
    get => this._objectType;
    set => this._objectType = value;
  }

  public bool IsChecked
  {
    get => this._isChecked;
    set
    {
      this._isChecked = value;
      if (!value)
        this.Preview = this.Name;
      if (this.checkStatus != null)
        this.checkStatus();
      this.NotifyPropertyChanged(nameof (IsChecked));
      if (this.Checked == null)
        return;
      this.Checked();
    }
  }

  public Dictionary<string, string> AttributeValue
  {
    get
    {
      if (this.attributeValue == null)
        this.attributeValue = new Dictionary<string, string>();
      return this.attributeValue;
    }
  }

  protected void NotifyPropertyChanged(string info)
  {
    if (this.PropertyChanged == null)
      return;
    this.PropertyChanged((object) this, new PropertyChangedEventArgs(info));
  }

  public event PropertyChangedEventHandler PropertyChanged;

  public int CompareTo(object obj)
  {
    return obj is CApRenameElement ? this.CompareTo(obj as CApRenameElement) : throw new NotImplementedException();
  }

  public int CompareTo(CApRenameElement other) => this.Compare(this, other);

  public int Compare(CApRenameElement x, CApRenameElement y) => string.Compare(x.Name, y.Name);
}
